﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace QuanLyCongDoanVien.UserControls
{
    public partial class ucTimKiemCDV : UserControl
    {
        public ucTimKiemCDV()
        {
            InitializeComponent();
        }

        private void ucTimKiemCDV_Load(object sender, EventArgs e)
        {
            txtHoTen.Enabled = false;
            txtMaCDV.Enabled = false;
            btnDongY.Enabled = false;
            dtgKetQua.Enabled = false;
        }

        private void txtMaCDV_TextChanged(object sender, EventArgs e)
        {
            if (txtMaCDV.Text.Trim() != "" && rdiMaCDV.Checked == true)
            {
                btnDongY.Enabled = true;
            }
            else
            {
                btnDongY.Enabled = false;
            }
        }

        private void txtHoTen_TextChanged(object sender, EventArgs e)
        {
            if (rdiHoTen.Checked == true && txtHoTen.Text.Trim() != "")
            {
                btnDongY.Enabled = true;
            }
            else
            {
                btnDongY.Enabled = false;
            }
        }

        private void btnDongY_Click(object sender, EventArgs e)
        {
            string maCDV = txtMaCDV.Text.Trim();
            string strHoTen = txtHoTen.Text.Trim();
            try
            {
                dtgKetQua.Enabled = true;
                dtgKetQua.DataSource = CongDoanVienBUS.TimKiem(maCDV, strHoTen, new ToCongDoanDTO());
                dtgKetQua.Columns["tocongdoanid"].Visible = false;
                dtgKetQua.Columns["tocongdoan"].Visible = false;
                dtgKetQua.Columns["tongiao"].Visible = false;
                dtgKetQua.Columns["tongiaoid"].Visible = false;
                dtgKetQua.Columns["dantoc"].Visible = false;
                dtgKetQua.Columns["dantocid"].Visible = false;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void rdiMaCDV_CheckedChanged(object sender, EventArgs e)
        {  
            txtMaCDV.Enabled = true;
            txtHoTen.Enabled = false;
            txtHoTen.Text = "";
        }

        private void rdiHoTen_CheckedChanged(object sender, EventArgs e)
        {
            txtHoTen.Enabled = true;
            txtMaCDV.Enabled = false;
            txtMaCDV.Text = "";
        }
    }
}
